//
//  ViewController.m
//  CAShapeLayerDemo1
//
//  Created by 李煜 on 2024/5/13.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
	[super viewDidLoad];
	[self method1];
	[self method2];
	[self method3];
	[self method4];
}
- (void)method1 {
	UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
	view.backgroundColor = [UIColor systemBlueColor];
	[self.view addSubview:view];
	
	CGFloat x = view.bounds.size.width / 2.0;
	CGFloat y = view.bounds.size.height / 2.0;
	CGFloat radius = MIN(x, y) * 0.8;
	
	UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(x, y) radius:radius startAngle:0.0 endAngle:2 * M_PI clockwise:YES];
	[circlePath closePath]; // 确保路径闭合
	
	CAShapeLayer *circleLayer = [CAShapeLayer layer];
	circleLayer.path = circlePath.CGPath;
	circleLayer.strokeColor = [UIColor redColor].CGColor;
	circleLayer.fillColor = [UIColor clearColor].CGColor;
	circleLayer.lineWidth = 2.0;
	
	[view.layer addSublayer:circleLayer];
}

-(void)method2 {
	UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 200, 100, 100)];
	view.backgroundColor = [UIColor systemBlueColor];
	[self.view addSubview:view];

	CGRect rect = CGRectMake(10.0, 10.0, 100.0, 100.0);
	CGSize radii = CGSizeMake(10.0, 10.0);
	UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:radii];
	
	CAShapeLayer *circleLayer = [CAShapeLayer layer];
	circleLayer.path = path.CGPath;
	circleLayer.strokeColor = [UIColor redColor].CGColor;
	circleLayer.fillColor = [UIColor clearColor].CGColor;
	circleLayer.lineWidth = 2.0;
	
	[view.layer addSublayer:circleLayer];

}
-(void)method3 {
	UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 400, 100, 100)];
	view.backgroundColor = [UIColor systemBlueColor];
	[self.view addSubview:view];

	CGRect rect = CGRectMake(10.0, 10.0, 100.0, 100.0);
	CGSize radii = CGSizeMake(10.0, 10.0);
	UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:radii];

	CAShapeLayer *circleLayer = [CAShapeLayer layer];
	circleLayer.path = path.CGPath;
	circleLayer.strokeColor = [UIColor redColor].CGColor;
	circleLayer.fillColor = [UIColor clearColor].CGColor;
	circleLayer.lineWidth = 2.0;
	
	[view.layer addSublayer:circleLayer];

}

-(void)method4 {
	UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 600, 100, 100)];
	view.backgroundColor = [UIColor systemBlueColor];
	[self.view addSubview:view];
	
	CGRect rect = CGRectMake(10.0, 10.0, 100.0, 100.0);
	CGSize radii = CGSizeMake(20.0, 10.0); // 水平方向半径大于垂直方向半径
	UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerAllCorners cornerRadii:radii];
	
	CAShapeLayer *circleLayer = [CAShapeLayer layer];
	circleLayer.path = path.CGPath;
	circleLayer.strokeColor = [UIColor redColor].CGColor;
	circleLayer.fillColor = [UIColor clearColor].CGColor;
	circleLayer.lineWidth = 2.0;
	
	[view.layer addSublayer:circleLayer];
	
}
@end
